#include <stdio.h>

#include <cv.h>
#include <highgui.h>

int main( int argc, char** argv )
{
    CvCapture* capture1 = 0;
    CvCapture* capture0 = 0;
    IplImage* frame1 = 0;
    IplImage* frame0 = 0;

    capture1 = cvCaptureFromCAM( 2 );
    capture0 = cvCaptureFromCAM( 1 );
    //capture = cvCaptureFromAVI("1.wmv");//播放视频 就换成这句

    int fps=12; //捕捉帧率
    //int fps = cvGetCaptureProperty(capture,CV_CAP_PROP_FPS); //视频帧率

    //printf("fps=%d\n",fps);

    CvVideoWriter* writer1 = 0; //保存就加上这句
    CvVideoWriter* writer0 = 0;
    int isColol=1;
    int frameW=640;
    int frameH=480;

    writer1=cvCreateVideoWriter("/home/song/Rout6.avi",CV_FOURCC('F','L','V','1'),fps,cvSize(frameW,frameH),isColol);
    writer0=cvCreateVideoWriter("/home/song/Lout6.avi",CV_FOURCC('F','L','V','1'),fps,cvSize(frameW,frameH),isColol);

    //cvResizeWindow( "摄像头1", 640, 480);
    //cvResizeWindow( "摄像头0", 640, 480);

    while(true) //一直读
    {
        frame1 = cvQueryFrame( capture1 );
        frame0 = cvQueryFrame( capture0 );

        cvWriteFrame(writer1,frame1 );
        cvWriteFrame(writer0,frame0 );

        cvShowImage( "摄像头1", frame1 ); //显示一帧图像
        cvShowImage( "摄像头0", frame0 );

        char c=cvWaitKey(20);//视频速度
        if(c==27) break;
    }

    cvReleaseVideoWriter(&writer1);
    cvReleaseVideoWriter(&writer0);
    cvReleaseImage(&frame1);
    cvReleaseImage(&frame0);
    cvReleaseCapture( &capture1 );
    cvReleaseCapture( &capture0 );
    cvDestroyWindow("摄像头1");
    cvDestroyWindow("摄像头0");
    return 0;
} 